import 'package:base_plugin/base_plugin.dart';
import 'package:dio/src/response.dart';

class HttpBankReconciliationsService {
  //检查是否有未完成的对比页面
  static Future<Response> checkBank() {
    return BaseConfig.httpBase.get('/api/bank_reconciliations/check', null);
  }

  static Future<Response> bankRecord(int id) {
    return BaseConfig.httpBase
        .get('/api/bank_reconciliations/$id/bank_records', null);
  }

  static Future<Response> paymentRecord(int bankId, int id, [String status]) {
    if (status == 'All') {
      return BaseConfig.httpBase
          .get('/api/bank_reconciliations/$bankId/payment_records', {});
    } else if (status == 'Matched') {
      return BaseConfig.httpBase
          .get('/api/bank_reconciliations/$bankId/payment_records', {
        'type': 'matched',
        'bank_reconciliation_record_id': id,
      });
    } else {
      return BaseConfig.httpBase
          .get('/api/bank_reconciliations/$bankId/payment_records', {
        'bank_reconciliation_record_id': id,
      });
    }
  }

  static Future<Response> reconcile(
      int bank_reconciliation_id, List<int> payment_ids) {
    return BaseConfig.httpBase.postJson('/api/bank_reconciliations/confirm', {
      'bank_reconciliation_id': bank_reconciliation_id,
      'payment_ids': payment_ids,
    });
  }

  static Future<Response> unDoReconcile(int bank_reconciliation_id) {
    return BaseConfig.httpBase.postJson('/api/bank_reconciliations/undo', {
      'bank_reconciliation_id': bank_reconciliation_id,
    });
  }

  //里面的status=open是没有match过，status=closed是已经match过。
  static Future<Response> match(
      int bank_reconciliation_id, List<int> payment_ids) {
    return BaseConfig.httpBase.postJson('/api/bank_reconciliations/match', {
      'bank_reconciliation_record_id': bank_reconciliation_id,
      'payment_ids': payment_ids,
    });
  }

}
